//
//  MyControl.m
//  test_demo
//
//  Created by ZhangCheng on 14-3-6.
//  Copyright (c) 2014年 ZhangCheng. All rights reserved.
//

#import "MyControl.h"

@implementation MyControl
//工厂模式   +方法

//label  button  imageView  View
+(UILabel*)createLabelWithFrame:(CGRect)frame Font:(int)font Text:(NSString*)text
{
    UILabel*label=[[UILabel alloc]initWithFrame:frame];
    //限制行数
    label.numberOfLines=0;
    //对齐方式
  //  label.textAlignment=NSTextAlignmentCenter;
    label.backgroundColor=[UIColor clearColor];
    label.font=[UIFont systemFontOfSize:font];
    //单词折行
//    label.lineBreakMode=NSLineBreakByWordWrapping;
    //默认字体颜色是白色
    label.font=[UIFont fontWithName:@"HiraginoSans-W3" size:font*PER_WIDTH];
    label.textColor=[UIColor blackColor];
    //自适应（行数~字体大小按照设置大小进行设置）
//    label.adjustsFontSizeToFitWidth=YES;
    label.text=text;
    return label;
}
+(UILabel*)createLabelWithFrame:(CGRect)frame Font:(int)font Text:(NSString*)text   Color:(UIColor*)color{
    UILabel*label=[[UILabel alloc]initWithFrame:frame];
    //限制行数
        label.numberOfLines=0;
    //对齐方式
    //  label.textAlignment=NSTextAlignmentCenter;
    label.backgroundColor=[UIColor clearColor];
    
    //单词折行
    //    label.lineBreakMode=NSLineBreakByWordWrapping;
    //默认字体颜色是白色
    label.font=[UIFont fontWithName:@"HiraginoSans-W3" size:font*PER_HEIGHT];
    label.font=[UIFont systemFontOfSize:font*PER_HEIGHT];
    label.textColor=color;
    //自适应（行数~字体大小按照设置大小进行设置）
    //    label.adjustsFontSizeToFitWidth=YES;
    label.text=text;
    return label;
}

+(UIButton*)createButtonWithFrame:(CGRect)frame ImageName:(NSString*)imageName Target:(id)target Action:(SEL)action Title:(NSString*)title
{
    UIButton*button=[UIButton buttonWithType:UIButtonTypeCustom];
    button.frame=frame;
    [button setTitle:title forState:UIControlStateNormal];
    button.titleLabel.font=[UIFont fontWithName:@"HiraginoSans-W3" size:10.];
    if (![imageName isEqualToString:@""]) {
        
        //设置背景图片，可以使文字与图片共存
        [button setBackgroundImage:[UIImage imageNamed:imageName] forState:UIControlStateNormal];
        
    }
   // [button setImage:[UIImage imageNamed:imageName] forState:UIControlStateNormal];//图片与文字，如果需要同时存在就需要图片足够小，详见人人项目按钮设置
    [button addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];
  return button;
}
+(UIImageView*)createImageViewWithFrame:(CGRect)frame ImageName:(NSString*)imageName
{
    UIImageView*imageView=[[UIImageView alloc]initWithFrame:frame];
    imageView.image=[UIImage imageNamed:imageName];
    imageView.userInteractionEnabled=YES;
    return imageView;
}
+(UIView*)viewWithFrame:(CGRect)frame
{
    UIView*view=[[UIView alloc]initWithFrame:frame];
    
    return view;

}
+(UITextField*)createTextFieldWithFrame:(CGRect)frame placeholder:(NSString*)placeholder passWord:(BOOL)YESorNO leftImageView:(UIImageView*)imageView rightImageView:(UIImageView*)rightImageView 
{
    UITextField*textField=[[UITextField alloc]initWithFrame:frame];
    //灰色提示框
    textField.placeholder=placeholder;
    
    //文字对齐方式
    textField.textAlignment=NSTextAlignmentLeft;
    textField.secureTextEntry=YESorNO;
    //边框
    textField.borderStyle=UITextBorderStyleRoundedRect;
    //键盘类型
    textField.keyboardType=UIKeyboardTypeEmailAddress;
    //关闭首字母大写
    textField.autocapitalizationType=NO;
    //清除按钮
    textField.clearButtonMode=YES;
    //左图片
    textField.leftView=imageView;
    
    textField.leftViewMode=UITextFieldViewModeAlways;
    //右图片
    textField.rightView=rightImageView;
    //编辑状态下一直存在
    textField.rightViewMode=UITextFieldViewModeWhileEditing;
    //自定义键盘
    //textField.inputView
    //字体
  //  textField.font=[UIFont systemFontOfSize:font];
    textField.font=[UIFont fontWithName:@"HiraginoSans-W3" size:14.*PER_WIDTH];
    //字体颜色
    textField.textColor=UIColorFromHex(0x999999);
    //圆角
    textField.layer.cornerRadius=8;
    
    //边框
    textField.layer.borderColor=UIColorFromHex(0xcccccc).CGColor;
    textField.layer.borderWidth=1;
    return textField;

}
#pragma  mark 适配器方法
+(UITextField*)createTextFieldWithFrame:(CGRect)frame placeholder:(NSString*)placeholder passWord:(BOOL)YESorNO leftImageView:(UIImageView*)imageView rightImageView:(UIImageView*)rightImageView Font:(float)font backgRoundImageName:(NSString*)imageName
{
   UITextField*text= [self createTextFieldWithFrame:frame placeholder:placeholder passWord:YESorNO leftImageView:imageView rightImageView:rightImageView ];
    text.background=[UIImage imageNamed:imageName];
    return  text;

}

+(UIButton*)createButtonWithFrame:(CGRect)frame ImageName:(NSString*)imageName Title:(NSString*)title
{
    UIButton*button=[UIButton buttonWithType:UIButtonTypeCustom];
    button.frame=frame;
    [button setTitle:title forState:UIControlStateNormal];
    //设置背景图片，可以使文字与图片共存
    [button setBackgroundImage:[UIImage imageNamed:imageName] forState:UIControlStateNormal];
    // [button setImage:[UIImage imageNamed:imageName] forState:UIControlStateNormal];//图片与文字，如果需要同时存在就需要图片足够小，详见人人项目按钮设置
    
    return button;
}


#pragma -mark 判断导航的高度
+(float)isIOS7{

    float height;
    if (IOS7) {
        height=64.0;
    }else{
        height=44.0;
    }
    
    return height;
}





@end
